class Solution
{
public:
    int countCollisions(string directions)
    {
        int n = directions.size();
        int front = 0;
        while (front < n)
        {
            if (directions[front] == 'L')
            {
                ++front;
            }
            else
            {
                break;
            }
        }
        int back = n - 1;
        while (back >= 0)
        {
            if (directions[back] == 'R')
            {
                --back;
            }
            else
            {
                break;
            }
        }
        int count = 0;
        for (int i = front; i <= back; ++i)
        {
            if (directions[i] != 'S')
            {
                ++count;
            }
        }
        return count;
    }
};